In [4]:
import math
import sympy
from sympy import latex
from IPython.display import HTML, display

%matplotlib notebook

sympy.init_printing()

OMA 2. kolokvij 2013/2014

1. naloga

Podana je funkcija $f(x)=x^2 e^{-x}$.


In [5]:
x = sympy.symbols('x')
f = lambda x: x**2 * sympy.E**(-x)

Doloci definicijsko obmocje ${\cal D}_f$ in izracunaj limiti v robovih ${\cal D}_f$.

Ker je eksponentna funkcija definirana povsod, je ${\cal D}_f = \mathbb{R}$.
$\displaystyle{\lim_{x\to\infty} x^2 e^{-x} = 0}.$
$\displaystyle{\lim_{x\to -\infty} x^2 e^{-x} = \infty}.$

Poisci nicle in stacionarne tocke funkcije $f$.


In [6]:
equation = sympy.Eq(f(x), 0)
equation


Out[6]:
$$x^{2} e^{- x} = 0$$

In [7]:
solutions = sympy.solve(equation)
s = 'Nicle: ${0}$'.format(latex(solutions))
display(HTML(s))


Nicle: $\left [ 0\right ]$

In [8]:
derivative = sympy.diff(f(x), x)
equation = sympy.Eq(derivative, 0)
equation


Out[8]:
$$- x^{2} e^{- x} + 2 x e^{- x} = 0$$

In [9]:
solutions = sympy.solve(equation)
s = 'Stacionarne tocke: ${0}$'.format(latex(solutions))
display(HTML(s))


Stacionarne tocke: $\left [ 0, \quad 2\right ]$

Narisi graf funkcije $f$.


In [10]:
sympy.plotting.plot(f(x), (x, -1, 5))


Out[10]:
<sympy.plotting.plot.Plot at 0x7f58e38b07f0>

2. naloga

Izracunaj nedoloceni integral racionalne funkcije $$\int \frac{x}{(x-1)(x-2)}.$$


In [14]:
f = lambda x: x/((x-1)*(x-2))
sympy.integrate(f(x))


Out[14]:
$$2 \log{\left (x - 2 \right )} - \log{\left (x - 1 \right )}$$

Z integracijo po delih izracunaj $$\int_{0}^{\pi}x\cos(x)dx.$$


In [15]:
f = lambda x: x*sympy.cos(x)
sympy.integrate(f(x))


Out[15]:
$$x \sin{\left (x \right )} + \cos{\left (x \right )}$$

3. naloga

Resi linearno diferencialno enacbo prvega reda $$ y' - \frac{y}{x} = 2x^2.$$


In [16]:
f = sympy.symbols('f', cls=sympy.Function)
equation = sympy.Eq(f(x).diff(x)-f(x)/x, 2*x**2)
equation


Out[16]:
$$\frac{d}{d x} f{\left (x \right )} - \frac{1}{x} f{\left (x \right )} = 2 x^{2}$$

In [17]:
solution = sympy.dsolve(equation, f(x))
solution


Out[17]:
$$f{\left (x \right )} = x \left(C_{1} + x^{2}\right)$$

Upostevajmo se robni pogoj.


In [18]:
equation = solution.subs(f(x), 2).subs(x, 1)
equation


Out[18]:
$$2 = C_{1} + 1$$

In [19]:
c1 = sympy.solve(equation)[0]
C1 = sympy.symbols('C1')
sympy.expand(solution.subs(C1, c1))


Out[19]:
$$f{\left (x \right )} = x^{3} + x$$

4. naloga

Turist si v cerkvi ogleduje 3m visoko okno, ki se nahaja 1m nad njegovimi ocmi. Kako dalec od stene, na kateri se nahajo okno, naj se postavi, da bo razlika kotov pod katerimi vidi spodnji in zgornji kot okna najvecja?

Najprej nastavimo enacbo. Kot, pod katerim iz razdalje $x$ vidimo spodnji del okna $\arctan(\frac{1}{x})$, zgorjnji del pa vidimo pod kotom $\arctan(\frac{4}{x})$.


In [20]:
f = lambda x: sympy.atan(4/x) - sympy.atan(1/x)
f(x)


Out[20]:
$$- \operatorname{atan}{\left (\frac{1}{x} \right )} + \operatorname{atan}{\left (\frac{4}{x} \right )}$$

Kandidati za resitev so stacionarne tocke zgornje funkcije, torej nicle njenega odvoda. Pri tem dodatno zahtevamo, da so resitve pozitivne.


In [24]:
x = sympy.symbols('x', positive=True)
equation = sympy.Eq(f(x).diff(x), 0)

equation


Out[24]:
$$- \frac{4}{x^{2} \left(1 + \frac{16}{x^{2}}\right)} + \frac{1}{x^{2} \left(1 + \frac{1}{x^{2}}\right)} = 0$$

In [25]:
solutions = sympy.solve(equation)
solutions


Out[25]:
$$\left [ 2\right ]$$

Postaviti se mora 2 metra od stene.